<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>收费信息</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
    <script type="text/javascript" src="../../script/jquery-1.10.2.min.js"></script>
    <style type="text/css">
        .upperCase
        {
            text-transform:uppercase;
        }
    </style>
</head>
<body>
    <div class="container" id="container">
        <div id="divSearch" class="weui_cells weui_cells_form" style="margin-top:0px">
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">号牌号码</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtHPHM" class="weui_input upperCase" value="贵A" placeholder="请输入号牌号码"/>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">号牌种类</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                 <select class="select" style="width: 250px" id="drpHPZL"> </select>
            </div>
            </div>
            <div class="weui_cell" style="display: none">
            <div class="weui_cell_hd"><label class="weui_label">累计行驶里程</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtLJXSLC" class="weui_input" placeholder="请输入累计行驶里程"/>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">收费类型</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                 <select class="select" style="width: 250px" id="drpSFLX" onchange="ChangeSFJE()"> </select>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">客户归属</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                 <select class="select" style="width: 250px" id="drpKHGS" > </select>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">收费代号</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                 <select class="select" style="width: 250px" id="drpSFDH" onchange="ChangeDH()"> </select>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">收费金额</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtSFJE" class="weui_input" type="number" pattern="[0-9]*" placeholder="请输入收费金额"/>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">收费员</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input id="txtSFY" class="weui_input" readonly="true" placeholder="请输入收费金额"/>
            </div>
            </div>
            <br>
            <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">备注</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                 <textarea id="txtYJBZ" class="weui_textarea" placeholder="请输入备注" rows="3"></textarea>
            </div>
            </div>
            <br>
        <div class="mainbutton">
            <a class="weui_btn weui_btn_primary" href="javascript:;" id="btnSubmitSFXX" onclick="SaveSFXX()"  > 提 交 </a>            
        </div>
    </div> 
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    apiready = function(){
        GetHPZL();
        GetSFLX();
        GetKHGS();
        GetSFDH();
        GetSFY();
    };

    function GetSFLX()
    {
        GetDicInfo('drpSFLX','ZYLX');
    }

    function GetDicInfo(vName,vSFLX)
    {
         var vUrlWrite = $api.getStorage('ServerUrlWrite');
         api.ajax({
            url: vUrlWrite + '/YSFSysServices/GetAllYSF_DIC/' + vSFLX,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
             var vDic =  ret.Data;
             $("#"+ vName).empty();
            for (var i = 0; i < vDic.length; i++) {
                $("#"+ vName).append($("<option value=\"" + vDic[i].ID + "\">" + vDic[i].SFMC + "</option>"));
            }
                
            }
        });
    }

    function GetKHGS()
    {
         GetDicInfo('drpKHGS','KHGS');
    }

    function GetSFY()
    {
        var vSFY = $api.getStorage('UserCHName');
        $("#txtSFY").val(vSFY);
    }

    function ChangeKHGS()
    {
        var vKHGS = $("#drpKHGS").val();
        var vUrlWrite = $api.getStorage('ServerUrlWrite');
         api.ajax({
            url: vUrlWrite + '/YSFSysServices/GetYSF_SFDHBySSKH/'+vKHGS,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
             var vSFDH =  ret.Data;
             $("#drpSFDH").empty();
            for (var i = 0; i < vSFDH.length; i++) {
                $("#drpSFDH").append($("<option value=\"" + vSFDH[i].ID + "\">" + vSFDH[i].SFMC + "[" + vSFDH[i].SFDH +"]" + "</option>"));
            }
             
             ChangeDH();   
            }
        });
    }

    function GetHPZL()
    {
         var vUrlWrite = $api.getStorage('ServerUrlWrite');
         api.ajax({
            url: vUrlWrite + '/YSFSysServices/GetAllHPZL',
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
             var vHPZL =  ret.Data;
             $("#drpHPZL").empty();
            for (var i = 0; i < vHPZL.length; i++) {
                $("#drpHPZL").append($("<option value=\"" + vHPZL[i].HPZLDH + "\">" + vHPZL[i].HPZL + "</option>"));
            }
                
            }
        });
    }

    function GetSFDH()
    {
         var vUrlWrite = $api.getStorage('ServerUrlWrite');
         api.ajax({
            url: vUrlWrite + '/YSFSysServices/GetAllYSF_SFDH',
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
             var vSFDH =  ret.Data;
             $("#drpSFDH").empty();
            for (var i = 0; i < vSFDH.length; i++) {
                $("#drpSFDH").append($("<option value=\"" + vSFDH[i].ID + "\">" + vSFDH[i].SFMC + "[" + vSFDH[i].SFDH +"]" + "</option>"));
            }
             
             ChangeDH();   
            }
        });
    }

    function ChangeDH()
    {
        var vID = $("#drpSFDH").val();
        var vUrlWrite = $api.getStorage('ServerUrlWrite');
         api.ajax({
            url: vUrlWrite + '/YSFSysServices/GetYSF_SFDHByKey/' + vID,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                var vSFDH =  ret.Data;
                $("#txtSFJE").val(vSFDH.SFJE);
            }
        });
    }

    function ChangeSFJE()
    {
        $("#txtSFJE").val('0');
    }

    function SaveSFXX()
    {
        var vClass = $("#btnSubmitSFXX").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }


        if(vEnable)
        {
            var vHPHM = $("#txtHPHM").val();
            var vHPZL = $("#drpHPZL").find("option:selected").text();
            var vHPZLDH = $("#drpHPZL").val();
            var vLJXSLC = $("#txtLJXSLC").val();
            var vSFLX = $("#drpSFLX").val();
            var vSFDH = $("#drpSFDH").val();
            var vKHGS = $("#drpKHGS").val();
            var vSFJE = $("#txtSFJE").val();
            var vSFY = $("#txtSFY").val();
            var vYJBZ = $("#txtYJBZ").val();

            if(vHPHM.length <= 5)
            {
                api.alert({
                    title: '提示',
                    msg: '请确认号牌号码是否输入正确！',
                }, function(ret, err){
                });

                return;
            }   

            api.confirm({
                title: '提示',
                msg: '是否要进行收费？',
                buttons: ['是', '否']
                }, function(ret, err) {
                    if( ret.buttonIndex == 1)
                    {
                        var vUrlWrite = $api.getStorage('ServerUrlWrite');
                         $.ajax({
                            type: 'Post',
                            url: vUrlWrite + '/YSFSysServices/SaveYSF_VEHICLE_INFO',
                            contentType: "application/json", //必须有
                            async: false,
                            dataType: "json", //表示返回值类型，不必须
                                //data: JSON.stringify({ 'UserName': 'admin', 'UserPwd': '123456' }),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
                            data: JSON.stringify({
                                'HPHM': vHPHM,
                                'HPZL': vHPZL,
                                'HPZLDH': vHPZLDH,
                                'LJXSLC': vLJXSLC,
                                'SFLX':vSFLX,
                                'KHGS':vKHGS,
                                'Y_SFDH': vSFDH,
                                'Y_SFJE': vSFJE,
                                'WJY': vSFY,
                                'YJBZ':vYJBZ
                            }),
                            success: function(ret) {
                                if (ret.IsSuccess) {
                                    RefreshSFHome();
                                } else {
                                    alert(ret.Message);
                                    $("#btnSubmitSFXX").addClass("weui_btn_primary");
                                    $("#btnSubmitSFXX").removeClass("weui_btn_default");
                                }
                            },
                            error: function(data, status, e) {
                                    alert(e);
                                    $("#btnSubmitSFXX").addClass("weui_btn_primary");
                                    $("#btnSubmitSFXX").removeClass("weui_btn_default");
                            }
                        });
                 }
            });
        }
    }  

     function RefreshSFHome()
    {
        api.openWin({
            name: 'win_sfhome',
            url: 'win_sfhome.html',
            bounces: false,
            delay: 200,
            reload:true,
        });

        api.closeWin({
            name: 'win_sfinfo',
            url: 'win_sfinfo.html',
        });
    }

</script>